/**
 * 
 */
package com.kcwx.common.utils;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

/**
 * 
 * @author phx
 * @date 2023年3月9日 下午2:02:10
 */
public class ObjectUtil {

	public static <T> String validate(T t) {
		if (t == null) {
			return null;
		}
		Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
		Set<ConstraintViolation<T>> constraintViolations = validator.validate(t);
		String msg = "";
		for (ConstraintViolation<T> constraintViolation : constraintViolations) {
			msg += constraintViolation.getMessage() + ";";
		}
		return msg;
	}
}
